﻿app.controller("ngAdminController", function ($scope, $http, $location, projectListFactory) {
    if ($scope.username == "Admin" || $scope.username == "admin") {
        $scope.projectList = projectListFactory;
        $scope.adding = false;
        $scope.ImageUrls = [];
        $scope.addImage = function () {
            $scope.ImageUrls.push({ Url: "" });
        };
        $scope.addProject = function () {
            $scope.adding = true;
        };
        $scope.finishAdding = function (project) {
            console.log("start add");
            console.log(project);
            project.ImageUrls = $scope.ImageUrls;
            $http.post("/api/Project/", project).success(function (data) {
                $scope.projectList.push(data);
                project.Title = "";
                project.Description = "";
                project.WindowsAzureUrl = "";
                project.CodePlexUrl = "";
                project.LogoUrl = "";
                $scope.adding = false;
            }).error(function (data) {
                console.log("error " + data);
            });
        }
        $scope.editProject = function (id) {
            for(var project in projectList){
                if (project.Id == id) {
                    $scope.project = project;
                    break;
                }
            }
        }
    } else {
        $location.path("/");
    }
});